package com.example.makerspace.controller;
import com.example.makerspace.aop.Log;
import com.example.makerspace.dto.*;
import com.example.makerspace.service.ApplicationService;
import com.example.makerspace.utils.FileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;


/**
 * @author River
 * @version 1.0
 * @date 2023/9/27 21:40
 * @description:
 */
@Controller
@ResponseBody
@RequestMapping("/api/application")
@Api(tags = "PC端模块")
public class ApplicationController {
    @Resource
    private ApplicationService applicationService;
    private  static  String AdvancedAchievements="/home/ubuntu/java_project/static/demand/附件1：先进技术成果申请表.docx";
    private  static  String AdvancedDemand="/home/ubuntu/java_project/static/demand/附件3：先进技术产业化需求表.docx";

    private static  String devAdvancedAchievements="/static/attachment/test2/附件1：先进技术成果申请表 .docx";

    private static  String devAdvancedDemand="/static/attachment/test2/附件2：先进技术产业化需求表.docx";

    public  static   HttpServletRequest stockRequest;


    @PostMapping("/addApplication")
    public Result addApplication(@ModelAttribute ApplicationDTO applicationDTO) {
        return applicationService.addApplication(applicationDTO);
    }
    @Log("用户报名")
    @ApiOperation(value="填写用户信息报名表接口",notes ="填写用户信息报名表接口说明")
    @PostMapping(value = "/addApplication/v2")
    public Result addApplication(@ModelAttribute ApplicationV2DTO applicationV2DTO) {

        return applicationService.addApplication(applicationV2DTO);
    }


    @PostMapping("/save")
    public Result save(@ModelAttribute ApplicationDTO applicationDTO) {
        return applicationService.save(applicationDTO);
    }
    @Log("用户报名")
    @ApiOperation(value="填写用户信息报名表接口",notes ="填写用户信息报名表接口说明")
    @PostMapping("/save/v2")
    public Result save(@ModelAttribute ApplicationV2DTO applicationV2DTO) {
        return applicationService.save(applicationV2DTO);
    }

    @PostMapping("/submit")
    public Result submit(@ModelAttribute ApplicationDTO applicationDTO) {
        return applicationService.submit(applicationDTO);
    }

    @PostMapping("/submit/v2")
    public Result submit(@RequestBody ApplicationV2DTO applicationV2DTO) {
        return applicationService.submit(applicationV2DTO);
    }

    @GetMapping("/checkApplication")
    public Result checkApplication(HttpServletRequest request) {
        return applicationService.checkApplication(request);
    }

    /**
     * 报名检测接口
     */
    @ApiOperation(value="报名检测接口",notes ="报名检测接口说明")
    @GetMapping("/checkApplication/v2")
    public Result checkApplicationV2(HttpServletRequest request,Integer competitionParentId) {
        return applicationService.checkApplicationV2(request,competitionParentId);
    }

    /**
     * 状态流程
     * @param request
     * @param competitionParentId
     * @return
     */
    @ApiOperation(value="状态流程接口",notes ="状态流程接口说明")
    @GetMapping("/processStatus")
    public  Result processStatus(HttpServletRequest request,Integer competitionParentId){
        return  applicationService.processStatus(request,competitionParentId);
    }
    @Log("用户更新报名信息")
    @ApiOperation(value="更新用户信息报名表接口",notes ="更新用户信息报名表接口说明")
    @PostMapping("/updateApplication")
    public Result updateApplication(@ModelAttribute ApplicationDTO applicationDTO) {
        return applicationService.updateApplication(applicationDTO);
    }
    @Log("用户填写报名信息")
    @ApiOperation(value="填写用户信息报名表接口-v2",notes ="填写用户信息报名表接口-v2说明")
    @PostMapping("/updateApplication/v2")
    public Result updateApplication(@RequestBody Map<String, Object> params) {
        return applicationService.updateApplication(params);
    }
//    @ApiOperation(value="填写用户信息报名表接口",notes ="填写用户信息报名表接口说明")
    @PostMapping("/competitions")
    public PageResult competitions(@RequestBody PageRequest pageRequest) {
        return applicationService.competitions(pageRequest);
    }


    /**
     * 赛题检测
     * @param pageRequest 分页信息
     * @return
     */
    @ApiOperation(value="赛题检测接口",notes ="赛题检测接口说明")
    @PostMapping("/checkCompetition/v2")
    public Result checkCompetition(@RequestBody PageRequest pageRequest) {
        return applicationService.checkCompetition(pageRequest);
    }

    /**
     * 选择赛题
     * @param request
     * @param competitionId  赛题id
     * @param competitionParentId   父赛题id
     * @return
     */
    @ApiOperation(value="选择赛题接口",notes ="选择赛题接口说明")
    @GetMapping("/selectCompetition/v2")
    public Result selectCompetition(HttpServletRequest request,Integer competitionId,Integer competitionParentId) {
        return applicationService.selectCompetition(request,competitionId,competitionParentId);
    }

//    @ApiOperation(value="填写用户信息报名表接口",notes ="填写用户信息报名表接口说明")
    @PostMapping("/competitionDetail")
    public Result competitionDetail(@RequestBody Map<String, Object> params) {
        return applicationService.competitionDetail(params);
    }


    /**
     *个人实名认证
     * @param userAuthenticationDTO
     * @return
     */
    @Log("个人实名认证")
    @ApiOperation(value="个人实名认证接口",notes ="个人实名认证接口说明")
    @PostMapping("/authentication")
    public  Result  authentication(@ModelAttribute UserAuthenticationDTO userAuthenticationDTO){
        return  applicationService.authentication(userAuthenticationDTO);
    }

    /**
     * 企业实名认证
     * @param enterpriseCertificationDTO
     * @return
     */
    @Log("企业实名认证-API")
    @ApiOperation(value="企业实名认证接口",notes ="企业实名认证接口说明")
    @PostMapping("/certification")
    public  Result  certification(@ModelAttribute EnterpriseCertificationDTO enterpriseCertificationDTO){
        return  applicationService.certification(enterpriseCertificationDTO);
    }
    @Log("企业实名认证-审核")
    @ApiOperation(value="企业实名认证2.0接口",notes ="企业实名认证2.0接口说明")
    @PostMapping("/uploadCertification")
    public  Result  uploadCertification(@ModelAttribute EnterpriseCertificationDTO enterpriseCertificationDTO){
        return  applicationService.uploadCertification(enterpriseCertificationDTO);
    }

    @ApiOperation(value="搜索企业名接口",notes ="搜索企业名接口说明")
    @GetMapping("/searchEnterprise")
    public  Result  searchEnterprise(@RequestParam("entName") String entName){
        return  applicationService.searchEnterprise(entName);
    }


    /**
     * 更换认证方式接口
     * @param id  0-个人认证  1-企业认证
     * @param username 用户名
     * @return
     */
    @ApiOperation(value="更换认证方式接口",notes ="更换认证方式接口说明")
    @GetMapping("/replacementCertification")
    public  Result  replacementCertification(@RequestParam("id")Integer id,@RequestParam("username")String username){
        return  applicationService.replacementCertification(id,username);
    }
    /**
     * 下载先进技术成果申请表接口
     * @param response
     */
    @Log("下载先进技术成果申请表")
    @ApiOperation(value="下载先进技术成果申请表接口",notes ="下载先进技术成果申请表接口说明")
    @GetMapping("/downloadAdvancedAchievements")
    public  void downloadAdvancedAchievements(HttpServletResponse response){
        FileUtils.downloadFile3(response,devAdvancedAchievements);
    }

    /**
     * 下载先进技术产业化需求接口
     * @param response
     */
    @Log("下载先进技术产业化需求表")
    @ApiOperation(value="下载先进技术产业化需求接口",notes ="下载先进技术产业化需求接口说明")
    @GetMapping("/downloadAdvancedDemand")
    public  void downloadAdvancedDemand(HttpServletResponse response){
        FileUtils.downloadFile3(response,devAdvancedDemand);
    }


    /**
     * 上传先进技术产业化需求和先进技术成果文档
     * @param stageFormDTO
     */
    @ApiOperation(value="上传先进技术产业化需求和先进技术成果文档接口",notes ="上传先进技术产业化需求和先进技术成果文档说明")
    @PostMapping("/uploadDocument")
    public  Result uploadDocument(@ModelAttribute  StageFormDTO stageFormDTO){
        return  applicationService.uploadDocument(stageFormDTO);
    }





    /**
     * 下载企业认证附件
     * @param response
     */
    @ApiOperation(value="下载企业认证附件接口",notes ="下载企业认证附件接口说明")
    @GetMapping("/download")
    public  void download(HttpServletResponse response){
        FileUtils.downloadFile2(response);
    }

    @Log("审核企业认证")
    @ApiOperation(value="更新企业认证的信息接口",notes ="更新企业认证的信息接口说明")
    @PostMapping("/updateCertification")
    public  Result  updateCertification(@RequestBody EnterpriseCertificationDTO enterpriseCertificationDTO){
        return  applicationService.updateCertification(enterpriseCertificationDTO);
    }
    @ApiOperation(value="检测赛题接口",notes ="检测赛题接口说明")
    @PostMapping("/checkQuestions")
    public  Result checkQuestions(@RequestBody ApplicationV2DTO applicationV2DTO){
        return  applicationService.checkQuestions(applicationV2DTO);
    }

    /**
     * 赛题报名
     * @param applicationV2DTO 请求参数
     * @return
     */
    @Log("赛题报名")
    @ApiOperation(value="赛题报名接口",notes ="赛题报名接口说明")
    @PostMapping("/questionsRegistration")
    public  Result questionsRegistration(@ModelAttribute ApplicationV2DTO applicationV2DTO){
        return  applicationService.questionsRegistration(applicationV2DTO);
    }

    /**
     * 赛题提交
     * @param competitionSubmissionDTO
     * @return
     */
    @Log("赛题提交")
    @ApiOperation(value="赛题提交接口",notes ="赛题提交接口说明")
    @PostMapping("/questionSubmit")
    public  Result  questionSubmit(@ModelAttribute CompetitionSubmissionDTO competitionSubmissionDTO){
        return  applicationService.questionSubmit(competitionSubmissionDTO);
    }

    /**
     * 展示赛题提交
     * @return
     */
    @Log("展示赛题提交")
    @ApiOperation(value="展示赛题提交接口",notes ="展示赛题提交接口说明")
    @GetMapping("/showQuestionSubmit")
    public  Result showAllQuestionSubmit(String username,Integer competitionId){
        return  applicationService.showAllQuestionSubmit(username,competitionId);
    }


    /**
     * 修改赛题提交
     * @return
     */
    @Log("展示赛题提交")
    @ApiOperation(value="修改赛题提交接口",notes ="修改赛题提交接口说明")
    @PostMapping("/updateQuestionSubmit")
    public  Result updateQuestionSubmit(@ModelAttribute CompetitionSubmissionDTO competitionSubmissionDTO){
        return  applicationService.updateQuestionSubmit(competitionSubmissionDTO);
    }

    /**
     * 修改赛题报名
     * @param userCompetitionRelationShipDTO
     * @return
     */
    @Log("修改赛题报名")
    @ApiOperation(value="修改赛题报名接口",notes ="填写用户信息报名表接口说明")
    @PostMapping("/updateCompetition")
    public  Result updateCompetition(@RequestBody UserCompetitionRelationShipDTO userCompetitionRelationShipDTO){
        return  applicationService.updateCompetition(userCompetitionRelationShipDTO);
    }

    /**
     * 展示活动
     * @param pageRequest
     * @return
     */
    @ApiOperation(value="展示活动接口",notes ="展示活动接口说明")
    @PostMapping("/listApplication")
    public   Result   listApplication(@RequestBody PageRequest pageRequest){
        return  applicationService.listApplication(pageRequest);
    }

    /**
     * 活动的模糊查询
     * @param pageRequest
     * @return
     */
    @ApiOperation(value="活动的模糊查询接口",notes ="活动的模糊查询接口说明")
    @PostMapping("/vagueQuery")
    public Result vagueQuery(@RequestBody PageRequest pageRequest){
        return  applicationService.vagueQuery(pageRequest);
    }

    /**
     * 展示用户信息
     * @param request
     * @return
     */

    @ApiOperation(value="展示用户信息接口",notes ="展示用户信息接口说明")
    @GetMapping("/showUser")
    public  Result showUser(HttpServletRequest request){
        stockRequest=request;
        return  applicationService.showUser(request);
    }

    @ApiOperation(value="填写用户信息报名表接口",notes ="填写用户信息报名表接口说明")
    @GetMapping("/showUserCompetition")
    public  Result showUserCompetition(HttpServletRequest request,Integer competitionId){
        return  applicationService.showUserCompetition(request,competitionId);

    }

    /**
     * 修改用户信息
     * @param userInfoDTO
     * @return
     */
    @Log("修改用户信息")
    @ApiOperation(value="修改用户信息接口",notes ="修改用户信息接口说明")
    @PostMapping("/updateUser")
    public Result updateProducts(@ModelAttribute UserInfoDTO userInfoDTO){
        return  applicationService.updateUser(userInfoDTO);
    }

    /**
     * 上架产品
     * @param demandDTO
     * @return
     */
    @ApiOperation(value="上架产品接口",notes ="上架产品接口说明")
    @PostMapping("/addProducts")
    public  Result addProducts(DemandDTO demandDTO){
        return  applicationService.addProducts(demandDTO);
    }

    /**
     * 删除产品照片
     * @param deleteProductsDTO
     * @return
     */
    @ApiOperation(value="删除产品照片接口",notes ="删除产品照片接口说明")
    @PostMapping("/deleteProductPicture")
    public  Result deleteProductPicture(@RequestBody DeleteProductsDTO deleteProductsDTO){
        return  applicationService.deleteProductPicture(deleteProductsDTO);
    }


    /**
     * 展示产品
     * @param pageRequest
     * @return
     */
    @ApiOperation(value="展示产品接口",notes ="展示产品接口说明")
    @PostMapping("/showProducts")
    public Result showProducts(@RequestBody PageRequest pageRequest){
        return  applicationService.showProducts(pageRequest);
    }

    /**
     * 修改产品
     * @param demandDTO
     * @return
     */
    @Log("用户修改产品")
    @ApiOperation(value="修改产品接口",notes ="修改产品接口说明")
    @PostMapping("/updateProducts")
    public Result updateProducts(@ModelAttribute DemandDTO demandDTO){
        return  applicationService.updateProducts(demandDTO);
    }

    /**
     * 删除产品
     * @param id
     * @return
     */
    @Log("删除产品")
    @ApiOperation(value="删除产品接口",notes ="删除产品接口说明")
    @GetMapping("/deleteProducts")
    public Result deleteProducts(Integer id){
        return  applicationService.deleteProducts(id);
    }

    /**
     * 产品详情页
     * @param id  产品id
     * @return
     */
    @ApiOperation(value="产品详情页接口",notes ="产品详情页接口说明")
    @GetMapping("/detailProduct")
    public   Result   detailProduct(Integer id,Integer type){
        return  applicationService.detailProduct(id,type);
    }

    /**
     * 产品详情页/已经审核
     * @param id  产品id
     * @return
     */
    @Log("产品详情页/已经审核")
    @ApiOperation(value="产品详情页/已经审核接口",notes ="产品详情页/已经审核接口说明")
    @GetMapping("/detailProductAndShow")
    public   Result   detailProductAndShow(Integer id){
        return  applicationService.detailProductAndShow(id);
    }

    /**r
     * 展示后台删除记录接口
     * @return
     */
    @ApiOperation(value="展示后台删除记录接口",notes ="展示后台删除记录说明")
    @GetMapping("/showDeleteRecord")
    public   Result   AllDeleteRecord(){
        return  applicationService.AllDeleteRecord();
    }

    /**
     * 公司其他产品
     * @param id  产品id
     * @return
     */
    @ApiOperation(value="公司其他产品接口",notes ="公司其他产品接口说明")
    @GetMapping("/showOtherProduct")
    public   Result   showOtherProduct(@RequestParam("id") Integer id,@RequestParam("username")String username){
        return  applicationService.showOtherProduct(id,username);
    }

    /**
     * 用户上架产品
     * @param demandDTO
     * @return
     */
    @Log("用户上架产品")
    @ApiOperation(value="用户上架产品接口",notes ="用户上架产品接口说明")
    @PostMapping("/addUserProducts")
    public   Result   addUserProducts(@ModelAttribute DemandDTO demandDTO){
        return  applicationService.addUserProducts(demandDTO);
    }

    /**
     * 查询用户产品
     * @param
     * @return
     */
    @ApiOperation(value="查询用户产品接口",notes ="查询用户产品接口说明")
    @PostMapping("/showUserProducts")
    public   Result   showUserProducts(@RequestBody PageRequest pageRequest){
        return  applicationService.showUserProducts(pageRequest);
    }

    /**
     * 展示用户赛题状态
     * @param request
     * @return
     */
    @ApiOperation(value="展示用户赛题状态接口",notes ="展示用户赛题状态接口说明")
    @GetMapping("/showCompetitionState")
    public  Result showCompetitionState(HttpServletRequest request){
        return  applicationService.showCompetitionState(request);
    }



    /**
     * 回显企业信息接口
     * @param request
     * @return
     */
    @ApiOperation(value="回显企业信息接口",notes ="回显企业信息接口说明")
    @GetMapping("/showEnterprise")
    public  Result showEnterprise(HttpServletRequest request){
        return  applicationService.showEnterprise(request);
    }


    /**
     * 查看表单接口
     * @param request
     * @return
     */
    @ApiOperation(value="查看表单接口",notes ="查看表单接口说明")
    @GetMapping("/showTable")
    public  Result showTable(HttpServletRequest request){
        return  applicationService.showTable(request);
    }





}
